//
//  FristTableViewCell.m
//  Funny
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 King. All rights reserved.
//

#import "FristTableViewCell.h"

@implementation FristTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.name = [[UILabel alloc]init];
        self.name.font = [UIFont systemFontOfSize:19];
        [self.contentView addSubview:self.name];
        
        self.address = [[UILabel alloc]init];
        [self addSubview:self.address];
        self.address.numberOfLines = 2;
        self.address.font = [UIFont systemFontOfSize:14];
        self.address.textColor = [UIColor grayColor];
        
        self.jianjie = [[UILabel alloc]init];
        self.jianjie.numberOfLines = 0;
        self.jianjie.lineBreakMode = NSLineBreakByWordWrapping;
        self.jianjie.contentMode = UIViewContentModeBottom;
        self.jianjie.font = [UIFont systemFontOfSize:13];
        self.jianjie.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.jianjie];
        
        [self creatCollection];
    }
    return self;
}

- (void)creatCollection
{
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc ]init];
    flow.minimumInteritemSpacing = 0;
    flow.minimumLineSpacing = 8;
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flow.itemSize = CGSizeMake(SelfWidth / 3 - 30, SelfWidth / 3 - 30);
    
    /**
     广告栏的图片定义
     */
    self.collection =  [[UICollectionView alloc]initWithFrame:CGRectMake(0, 200, SelfWidth - 100, SelfWidth / 3 - 30) collectionViewLayout:flow];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.contentSize = CGSizeMake(SelfWidth * 3, 0);
    _collection.showsHorizontalScrollIndicator = NO;
    _collection.backgroundColor = [UIColor whiteColor];
    [_collection registerClass:[CityintroductCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    [self addSubview:_collection];
}

- (void)setArr:(NSArray *)arr
{
    _arr = arr;
    [self.collection reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CityintroductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.url = self.arr[indexPath.row];
    return cell;
}

- (void)layoutSubviews
{
    self.name.frame = CGRectMake(20, 10, 300, 30);
    self.address.frame = CGRectMake(20, 38, SelfWidth - 40, 30);
    self.jianjie.frame = CGRectMake(20, 66, SelfWidth - 40, 100);
    self.collection.frame = CGRectMake(10, 190, SelfWidth - 20, SelfWidth / 3);
}

- (void)setModel:(MainAnuseModel *)model
{
    self.name.text = model.name;
    if ([[model.baseinfo objectForKey:@"brief"] isEqualToString:@""]) {
        self.jianjie.text = @"简介:\n暂无介绍\n\n\n\n\n\n\n";
    }
    else
    self.jianjie.text = [NSString stringWithFormat:@"简介:  %@\n\n\n\n\n\n\n\n",[model.baseinfo objectForKey:@"brief"]];
    self.address.text = [NSString stringWithFormat:@"地址:  %@",[model.baseinfo objectForKey:@"address"]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
